<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size='small'  style='margin-top: 10px;' icon="el-icon-menu">首页</el-button>
			</router-link>
		</div>
		<!-- 模糊搜索条件 -->
		<div class="search">
			<el-button type="text" size="small" class="add btn" style=' text-decoration:underline;' v-if="ss" @click='gd'>更多</el-button>
            <el-button type="text" size="small" class="add btn" style=' text-decoration:underline;' v-if="ss1" @click='gd1'>更多</el-button>
			<div class="search-item">
            	<span>关键字</span>
                <el-input placeholder="请输入名字或电话"  class="code-search" v-model="vkeyword"  @keyup.enter.native="search" icon="search"></el-input>
            </div>
            <div class="search-item">
                 <el-select v-model="vpx" clearable  class="code-search" placeholder="按剩余课时排序" @change='search'>
					<el-option :label="v.mc" :value="v.id" v-for="v in pxcomboxlist"></el-option>
			     </el-select>
            </div>
			
			<!--<div class="search-item">
				<el-input placeholder="请输入学生姓名" class="code-search" v-model="studentName" icon="search"></el-input>
			</div>-->
			<el-button type="primary" size='small' class="btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
		</div>
		
		<div class="search1" v-if='aa'>
            <div class="search-item">
            	<span>剩余课时</span>
                <el-input v-model="syks" placeholder="请输入" style="width: 100px;"  @keyup.enter.native="search" icon="search"></el-input>
            </div>
            <div class="search-item">
				<span>缴费状态</span>
				<el-select v-model="iswc" placeholder="请选择状态" class="code-search" @change="search">
						<el-option label="全部"  value=""></el-option>
						<el-option label="已完成" value="Y"></el-option>
						<el-option label="未完成" value="N"></el-option>
				</el-select>
			</div>
			<div class="search-item">
                 <el-select v-model="vbjid" clearable  class="code-search" placeholder="请选择班级名">
					<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
			     </el-select>
            </div>
        </div>
		<!-- 数据表格展示区域 -->
		<el-table 
			:data="dataList" 
			:cell-style="styletest" 
			:v-loading="false" 
			element-loading-text="拼命加载中" 
			size="small"
			border 
			stripe 
			align="center" 
			class="admin-table" 
			:row-class-name="tableRowClassName" 
			@select="checkSelect" 
			@select-all="checkall">

			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                :sortable = "v.sortable"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference">
                        <div v-if="scope.column.property == 'zwm'" @click="componentsShow('info1',scope)">
                            <img
                            :src="scope.row.xb == '男' ? $store.state.sexImg.boy : $store.state.sexImg.girl"
                            style="width:20px;vertical-align:middle; float: left;"
                            v-if="scope.column.property == 'zwm'">
                            <span style="vertical-align:middle;">{{ scope.row[scope.column.property] }}</span>
                        </div>
                        <span style="vertical-align:middle;" v-else>{{ scope.row[scope.column.property] }}</span>

                    </div>
                </template>
            </el-table-column>

			<el-table-column label="操作" width="180px" align="center">
				<template scope="scope">
					<!--<el-button size="small" type="info"  @click="componentsShow(v.type,scope)" v-for="v in portBntList">{{v.name}}</el-button>-->
					<!--<el-button size="small" type="primary" v-if="scope.row.btnzt.substring(0,1) == 'Y'" @click="componentsShow('info',scope)">详情</el-button>-->
					<!--<el-button size="small" type="warning" v-if="scope.row.btnzt.substring(1,2) == 'Y'" @click="componentsShow('renew',scope)">补交</el-button>
					<el-button size="small" type="danger" v-if="scope.row.btnzt.substring(2,3) == 'Y'" @click="componentsShow('qftz',scope)">催缴通知</el-button>-->
					
					<el-button size="mini" type="warning"  @click="componentsShow('bujiao',scope)">缴费</el-button>
					<el-button size="mini" type="danger"  :disabled='scope.row.qfje<=0' @click="componentsShow('qftz',scope)">催缴通知</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页查询区域 -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageindex" :page-sizes="pagesizes" :page-size="pagesize" :layout="layout" :total="total" class="class-page">
		</el-pagination>
		<!-- 各个组件显示区域 -->
		<!--补交-->
		<AddComponent v-if="portComponents.bujiao.toggle" @close="componentsHide" :params="portComponents.bujiao.params" ></AddComponent>
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- 物品详情 -->
		<DetailsComponent v-if="portComponents.details.toggle" @close="componentsHide" :params="portComponents.details.params"></DetailsComponent>
		
		<YujiaoComponent v-if="portComponents.yujiao.toggle" @close="componentsHide" :params="this.dataList"></YujiaoComponent>
		<!-- 续交组件 -->
		<RenewComponent v-if="portComponents.renew.toggle" @close="componentsHide" :params="portComponents.renew.params"></RenewComponent>
		<!-- 续交详情组件 -->
		<InfoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></InfoComponent>

		<Info1Component v-if="portComponents.info1.toggle" @close="componentsHide" :params="portComponents.info1.params"></Info1Component>

		<QftzComponent v-if="portComponents.qftz.toggle" @close="componentsHide" :params="portComponents.qftz.params"></QftzComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>

<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
//	 import AddComponent from '../baoming/add'
	import AddComponent from '@/view/cost/baoming/add'
	import DetailsComponent from './details'
	import RenewComponent from './renew'
	import YujiaoComponent from './yujiao'
	import Info1Component from 'view/educa/classManage/student/info'
	import InfoComponent from './info'
	import QftzComponent from './qftz'

	import qs from 'qs'
	export default {
		components: {
			AddComponent,
			LoadingComponent,
			Info1Component,
			YujiaoComponent,
			DetailsComponent,
			RenewComponent,
			InfoComponent,
			QftzComponent
		},
		data() {
			return {
				vpx:'',
				aa:false,
			    ss:true,
			    ss1:false,
				vbjid:'',
				syks:'',
				vkeyword:'',
				addbujiao:false,
				zwm: '',
				xsid: '',
				iswc: '',
				studentXh: '',
				studentName: this.$route.query.iid,
				// studentName:'',
				comboxlist: [],
				pxcomboxlist:[],
				studentPhone: '',
				studentClass: '',
				time: '',
				/*组件区域*/
				portComponents: {
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},
					details: {
						type: 'details',
						toggle: false,
						params: '',
						data: {}
					},
					renew: {
						type: 'renew',
						toggle: false,
						params: '',
						data: {}
					},
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					},
					info1: {
						type: 'info1',
						toggle: false,
						params: '',
						data: {}
					},
					qftz: {
						type: 'qftz',
						toggle: false,
						params: '',
						data: {}
					},
					yujiao: {
						type: 'yujiao',
						toggle: false,
						params: '',
						data: {}
					},
					bujiao: {
						type: 'bujiao',
						toggle: false,
						params: '',
						data: {}
					}
				},

				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [{
						prop: 'id',
						label: 'id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '120',
						headerAlign: 'center'
					}, 
					{
						prop: 'zwm',
						label: '姓名',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '130',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'bjmc',
						label: '班级名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '130',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'kcmc',
						label: '课程名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'yuer',
						label: '可用余额',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'ktyuer',
						label: '可退余额',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'ycje',
						label: '预存金额',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'qfje',
						label: '欠费金额',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'yjkc',
						label: '剩余课次',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '70',
						headerAlign: 'center'
					},
					{
						prop: 'sj',
						label: '账单时间',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '140',
						minWidth: '140',
						headerAlign: 'center'
					},
					{
						prop: 'cjcs',
						label: '催缴次数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '70',
						minWidth: '80',
						headerAlign: 'center'
					},
					{
						prop: 'ydcs',
						label: '阅读次数',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '80',
						headerAlign: 'center'
					},
				],

				portBntList: [ //接口按钮列表
					{
						name: '补交',
						type: 'renew'
					},
					// {
					//     name:'物品详情',
					//     type:'details'
					// },
					{
						name: '缴费详情',
						type: 'info'
					},

				],

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: 1, //当前分页页码
				pagesizes: [12, 24, 36, 72], //显示个数的选择器选项
				pagesize: 12, //每页显示条目数
				total: 0, //总条数
			}
		},
		created() {
			if(this.$route.query.iid) {
				if(this.$route.query.frompage == 'zdxq') {
					this.componentsShow("info");
				}
			}
			//加载页面时调用
			this.$store.dispatch('changeTitle', '缴费催缴'); //修改title
			this.$store.dispatch('changeRouterIndex', '/cost/payjl'); //修改路由
//			this.getcomboxlist();
            this.getcomlist();
            this.getpxcomlist();
			this.search(); //分页获取默认数据
			this.isLoading = true; //动画开始
		},
		mounted() {
			this.isLoading = false; //动画结束
		},
		methods: {
			gd(){
        		this.aa=true;
        		this.ss=false;
        		this.ss1=true;
        	},
        	gd1(){
        		this.aa=false;
        		this.ss=true;
        		this.ss1=false;
        	},
			bujiao(){
				this.addbujiao = true
			},
			showbj(){
				this.addbujiao = false
			},
			styletest(boj) {
				if(boj.columnIndex == 5) {
					if(this.dataList[boj.rowIndex].qfje >= 0) {
						return 'color:red'
					}
				}
				return '';
			},
			tableRowClassName(row, index) { //隔行变色颜色设置
				/*if ( index%4 == 0) {
				    return "table-cell-green";
				}else if( index%4 == 1 ){
				    return "table-cell-yellow";
				}else if( index%4 == 2 ){
				    return "table-cell-red";
				}else{
				    return "table-cell-blue"
				}*/
			},
			tableCellControl(scope) { //表格单元格控制CSS样式
              if (scope.row.qfje>=0 && scope.column.property == "qfje") {
                  return {
                      color:"red",
                  }
              }
			},
			cktz(type, scope) {
				var params3 = qs.stringify({
					xsid: scope.row.id
				});
				this.axios.post(this.$store.state.api + 'order/jftz', params3)
					.then(res => {
					}).catch(res => {})
			},
			getcomlist(){
          	 var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
                      yhid:logininfo.id+'',
                    xxid:logininfo.xxid+''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/getbj',  params2 )
                 .then(res => {
                 let data = res.data.data;
                  let list = data.list;
                  this.comboxlist = list;
                 }).catch(res => {
				})
          } ,
          getpxcomlist(){
          	 var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
                      yhid:logininfo.id+'',
                      xxid:logininfo.xxid+''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'order/pxfs',  params2 )
                 .then(res => {
                 let data = res.data.data;
                  let list = data.list;
                  this.pxcomboxlist = list;
                 }).catch(res => {
				})
          } ,
//			getcomboxlist() {
//				var logininfo = JSON.parse(localStorage.logininfo);
//				this.searchLoading = true;
//				var params2 = qs.stringify({
//					yhid: logininfo.id,
//					xxid: logininfo.xxid
//				})
//				//执行
//				this.axios.post(this.$store.state.api + 'order/getwczt', params2)
//					.then(res => {
//						let data = res.data.data;
//						let list = data.list;
//						this.comboxlist = list;
//					}).catch(res => {
//						this.searchLoading = false;
//					})
//			},
			search() { //查询搜索触发事件
				this.searchLoading = true;
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					px :this.vpx,
					bjid:this.vbjid,
					syks: this.syks,
					iswc: this.iswc,
					keyword: this.vkeyword,
					pageindex: this.pageindex+'',
					pagesize: this.pagesize+'',
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});
				this.axios.post(this.$store.state.api + 'xs/xsjflistzhxx', params3)
					.then(res => {
//						console.log(res,'kkkkkkkkkkkk')
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						this.xsid = res.data.data.list[0].xsid;
						this.zwm = res.data.data.list[0].zwm;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},

			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},

			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				console.log(selection, row)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				// console.log(selection)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
//				console.log(type, data, 11111111111111111)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						console.log(this.portComponents[i])

						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;

						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id

						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;

						} else {
							return;
						}
						return;
					}
				}

			},
			componentsHide(setting) { //关闭组件
				this.search();
//				this.$store.dispatch('changeTitle', '补交账单管理'); //修改title
				this.portComponents.info1.toggle = false;
				this.portComponents.bujiao.toggle = false;
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						this.search();
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}

		},
		computed: {
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		position: relative;
		.btn {
			height: 30px;
			padding: 0 10px;
			margin-top: 8px;
		}
		.submit {
			width: 80px;
		}
		.code-search {
			 max-width: 145px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
		}
		/*.admin-table {
			margin-top: 10px;
		}*/
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
		}
		.but1 {
			width: 30%;
			height: 50px;
			line-height: 50px;
			float: left;
		}
		.search {
			width: 70%;
			height: 50px;
			line-height: 50px;
			float: right;
			text-align: right;
		}
		.search1{
			width: 50%;
			height: 50px;
			float: right;
			line-height: 50px;
			margin-right: 0px;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 5px;
		}
	}
</style>